package com.dc.refactoring._0_入门;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * Description: 客户
 * @author: gdc
 * @date: 2020/11/10
 * @version 1.0
 */
@Data
@Accessors(chain = true)
public class Customer {

    /**
     * 客户名称
     */
    private String name;
    /**
     * 租赁信息列表
     */
    private List<Rental> rentals = Lists.newArrayList();

    /**
     * 添加租赁信息
     *
     * @param rental 租赁信息
     */
    public void addRental(Rental rental) {
        rentals.add(rental);
    }


    public String statement() {
        String result = getName() + "的租赁记录信息为：\n";
        for (Rental rental : rentals) {
            // 展示电影明细
            result += "\t" + rental.getMovie().getTitle() + "\t" + rental.getCharge() + "\n";
        }

        result += "总金额为：" + getTotalCharge() + "\n";
        result += "你获得的积分为：" + getTotalFrequentRenterPoints() + "\n";
        return result;
    }

    private double getTotalCharge(){
        // 总金额
        double result = 0;
        for (Rental rental : rentals) {
            result += rental.getCharge();
        }
        return result;
    }

    private int getTotalFrequentRenterPoints(){
        // 积分累计
        int result = 0;
        for (Rental rental : rentals) {
            // 计算积分
            result += rental.getFrequentRenterPoints();
        }
        return result;
    }

}